{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from gs_quant.risk import RollFwd, MarketDataPattern, MarketDataShock, MarketDataShockBasedScenario,MarketDataShockType\n",
    "from gs_quant.session import Environment, GsSession\n",
    "from gs_quant.common import PayReceive, Currency\n",
    "from gs_quant.instrument import IRSwap"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# external users should substitute their client id and secret; please skip this step if using internal jupyterhub\n",
    "GsSession.use(Environment.PROD, client_id=None, client_secret=None, scopes=('run_analytics',))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# define swap\n",
    "swap = IRSwap(termination_date='10y', notional_currency=Currency.USD, pay_or_receive=PayReceive.Pay, fixed_rate=0.007)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 1bp Spot Shock\n",
    "ir_1bp_scenario = MarketDataShockBasedScenario(shocks={\n",
    "    MarketDataPattern('IR', 'USD') : MarketDataShock(shock_type=MarketDataShockType.Absolute, value=1e-4),\n",
    "    MarketDataPattern('IR Reset', 'USD-3m') : MarketDataShock(shock_type=MarketDataShockType.Absolute, value=1e-4)\n",
    "})\n",
    "\n",
    "# Roll Forward 22b\n",
    "rollfwd_22b_scenario = RollFwd(date='22b', holiday_calendar='NYC')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Roll Forward 22b and apply 1bp Spot Shock\n",
    "with rollfwd_22b_scenario, ir_1bp_scenario:\n",
    "    rollfwd_22b_then_ir_1bp_price = swap.price()\n",
    "    \n",
    "# Look at the difference between scenario and base prices\n",
    "print('Base price:     {:,.2f}'.format(swap.price()))\n",
    "print('Scenario price: {:,.2f}'.format(rollfwd_22b_then_ir_1bp_price))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
